Yes — Scanner objects have many input methods.
Echo.java
Here is the actual Java program.
It reads characters from the keyboard
and creates a String object to contain them.
A reference to the object is put in inData.
Then it sends the characters from that String to the monitor.
import java.util.Scanner;
class Echo
{
public static void main (String[] args)
{
String inData;
Scanner scan = new Scanner( System.in );
System.out.println("Enter the data:");
inData = scan.nextLine();
System.out.println("You entered:" + inData );
}
}
The line import java.util.Scanner;
says to use Scanner from the package java.util.
The java.io package is imported automatically.
Here is a run of the program:
It would be beneficial to your future endeavors if you created a source program, compiled, and ran it.
Could the user include digits like 123 in the input characters?